<!DOCTYPE html>
<html class="bg-black">
<head>
    <meta charset="UTF-8">
    <title>Pihome | Log in</title>
    <link rel="shortcut icon" href="/static/img/icon.png">
    <meta content='width=device-width, initial-scale=1, maximum-scale=1, user-scalable=no' name='viewport'>
    <!-- bootstrap 3.0.2 -->
    <link href="/static/css/bootstrap.min.css" rel="stylesheet" type="text/css" />
    <!-- font Awesome -->
    <link href="/static/css/font-awesome.min.css" rel="stylesheet" type="text/css" />
    <!-- Theme style -->
    <link href="/static/css/AdminLTE.css" rel="stylesheet" type="text/css" />

    <!-- HTML5 Shim and Respond.js IE8 support of HTML5 elements and media queries -->
    <!-- WARNING: Respond.js doesn't work if you view the page via file:// -->
        <!--[if lt IE 9]>
          <script src="https://oss.maxcdn.com/libs/html5shiv/3.7.0/html5shiv.js"></script>
          <script src="https://oss.maxcdn.com/libs/respond.js/1.3.0/respond.min.js"></script>
          <![endif]-->
      </head>
      <body class="bg-black">

        <div class="form-box" id="login-box">
            <div class="header">Sign In</div>
            <form action=""  method="post">
               {% csrf_token %}
               <div class="body bg-gray">
                <div class="form-group">
                    <label>email</label>
                    <input type="text" name="username" class="form-control" placeholder="User ID"/>
                </div>
                <div class="form-group">
                    <label>password</label>
                    <input type="password" name="password" class="form-control" placeholder="Password"/>
                </div>          
                <div class="form-group">
                    <input type="checkbox" name="remember_me"/> Remember me
                </div>
                <div class="form-group">
                    <label class="control-label" style="color: #f56954; display:None;"></label>       
                </div>
            </div>
            <div class="footer">                                      
                <button id="submit" type="submit" class="btn bg-olive btn-block">Sign me in</button>  
                <a href="{% url 'PiApp.views.register_view'%}" class="text-center">Register a new membership</a>
            </div>
        </form>

    </div>


    <!-- jQuery 2.0.2 -->
    <script src="/static/js/jquery.min.js"></script>
    <!-- Bootstrap -->
    <script src="/static/js/bootstrap.min.js" type="text/javascript"></script>        
    <script>
    $(function() {
        $('form').submit(function() {
            var form_data = $('form').serialize()
            $.ajax({
                cache: true,
                type: "POST",
                url:'',
                data: form_data,// 你的formid
                dataType: "json",
                async: false,
                error: function(request) {
                    $('.control-label').html('Connection error');
                    $('.control-label').css("display", "block");
                },
                success: function(data) {
                    if(data['msg'] != 'ok') {
                        $('.control-label').html('Incorrect username or password.');
                        $('.control-label').css("display", "block");
                    } else {
                        window.location.replace("{{ next_url }}");
                    }                
                }
            });

            return false;
        });
    });
    </script>

</body>
</html>